﻿using System;
using System.Linq;
using System.Windows;
using PairingMatrix.Common.Enum;

namespace PairingMatrix.Model
{
    public class PairedWithModel : BusinessModelBase
    {
        private readonly PairModel _pairModel;
        private readonly string _teamMemberName;

        public PairedWithModel(PairModel pairModel, string teamMemberName)
        {
            _pairModel = pairModel;
            this._teamMemberName = teamMemberName;
        }

        public TeamMemberModel Member
        {
            get { return _pairModel.Members.FirstOrDefault(pairedWith => pairedWith.Name != _teamMemberName) ?? _pairModel.Members[0]; }
        }

        public int NumberOfTimesPaired
        {
            get { return _pairModel.Cards.Count; }
        }

        public PairingLevel PairingLevel
        {
            get {
                    var numberOfProjectCards = _pairModel.Cards.Count;
                    if (numberOfProjectCards >= 0 && numberOfProjectCards <= 1)
                        return PairingLevel.ShouldDefinitelyPair;
                    if (numberOfProjectCards == 2)
                        return PairingLevel.TryToPairMore;
                    if (numberOfProjectCards == 3)
                        return PairingLevel.CanPair;
                    if (numberOfProjectCards > 3 && numberOfProjectCards <= 5)
                        return PairingLevel.AvoidPairing;
                    return PairingLevel.ShouldDefinitelyNotPair;
                 }
            
        }

        public void IncrementPairing()
        {
//            var cardWallInstanceOnADates = _pairModel.DataService.GetCardWallInstancesBetween(DateTime.MinValue, DateTime.MinValue.AddYears(10));
//            var cardNumber = "Unspecified";
//            _pairModel.DataService.SetProjectCardInDevelopmentStage(DateTime.MinValue, cardNumber, "New", new Point(-100, -100));
//            _pairModel.DataService.AttachTeamMemberToProjectCard(DateTime.MinValue.AddDays(cardWallInstanceOnADates.Count), _pairModel.Members[0].Name, cardNumber, new Point(0, 0));
//            _pairModel.DataService.AttachTeamMemberToProjectCard(DateTime.MinValue.AddDays(cardWallInstanceOnADates.Count), _pairModel.Members[1].Name, cardNumber, new Point(0, 0));
        }
    }
}